<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      canvas {
        background: #0a0;
        display: block;
        margin: 0 auto;
      }
    </style>
  </head>
  <body>
    <script>
      const canvas = document.createElement("canvas");
      canvas.width = 750;
      canvas.height = 750;
      document.body.append(canvas);
      const ctx = canvas.getContext("2d");
      // 画圆弧
      for (let i = 1; i < 15; i++) {
        // 画横线
        ctx.moveTo(50, 50 * i);
        // 转折点
        ctx.lineTo(700, 50 * i);
        ctx.stroke();
        // 画竖线
        ctx.moveTo(50 * i, 50);
        ctx.lineTo(50 * i, 700);
        ctx.stroke();
        // 转折点;
      }

      canvas.addEventListener("click", (e) => {
        const x = e.offsetX;
        const y = e.offsetY;
        const xIndex = Math.round((x) / 50) * 50;
        const yIndex = Math.round((y) / 50) * 50;
        ctx.beginPath();
        ctx.arc(xIndex, yIndex, 25, 0, Math.PI * 2, false);
        ctx.fill();
        ctx.stroke();
        ctx.closePath();
      });
    </script>
  </body>
</html>
